
// 迭代器简单实现 , from async iterator
// iterator(funArr)
var fn1 = function(str){console.log('fn1'+str)};
var fn2 = function(str){console.log('fn2'+str)};
var fn3 = function(str){console.log('fn3'+str)};
var jobs = [fn1,fn2,fn3];

var iterator = function(arr){
	var makeCall = function(index){
		var fn = function(){
			arr[index].apply(null,arguments);
		};
		fn.next = function(){
			return index<arr.length-1? makeCall(index+1) : null;
		};
		return fn;
	}
	return makeCall(0);
}

var it = iterator(jobs); // it = 第一个函数,it()执行第一个函数,it.next()下一个函数
while (it !== null) {
	// console.log(it);
	it(''); // execute
	it = it.next();
}
